package LeetCode.leetcode;

/**
 * 爬楼梯
 * @author: leiwenkang02@meituan.com
 * @date: 2018/8/24
 * @time: 13:01
 */
public class Test70爬楼梯 {
    public int climbStairs(int n) {
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        int step1 = 1;
        int step2 = 2;
        int result = 0;
        for (int i = 3; i <= n; i++) {
            result = step1 + step2;
            step1 = step2;
            step2 = result;
        }
        return result;
    }

    public int climbStairs2(int n) {
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        return climbStairs(n - 2) + climbStairs(n - 1);
    }
}
